package com.sgb.kjwl.pop;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.businessmanagement.CompanyEntity;
import com.sgb.kjwl.view.ui.activity.self.JoinCompanyActivity;
import com.sgb.kjwl.view.ui.activity.self.authentication.AuthActivity3;
import com.sgb.kjwl.view.ui.adapter.self.CompanyChangeAdapter;
import com.swgk.core.dialog.BaseTopDialog;
import com.swgk.core.dialog.DialogViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class CompanyChangeDialog extends BaseTopDialog {
    private DialogClickCallBack dialogClickCallBack;
    private CompanyChangeAdapter goodsTypeAdapter;
    public CompanyChangeDialog(Context context, DialogCallBack dialogCallBack,View view) {
        super(context, dialogCallBack,view);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.popwindow_self_fragment_company;
    }

    @Override
    protected void initView(DialogViewHolder holder, Bundle savedInstanceState) {
        RecyclerView recyclerView = holder.itemView.findViewById(R.id.goods_type_list);
        goodsTypeAdapter = new CompanyChangeAdapter(context,null);
        goodsTypeAdapter.setItemSelect(true);
        goodsTypeAdapter.setDefItem(-1);
        recyclerView.setLayoutManager(new GridLayoutManager(context,1));
        recyclerView.setAdapter(goodsTypeAdapter);
        goodsTypeAdapter.setOnItemClick(new AdapterOnItemClick<CompanyEntity>() {
            @Override
            public void onItemClick(CompanyEntity provinceEntity, int position) {
                dialogClickCallBack.onItemClick(provinceEntity,position);
            }
        });
        holder.itemView.findViewById(R.id.ll_create_group).setOnClickListener(v -> {
            AuthActivity3.start(getContext());
            dismiss();
        });
        holder.itemView.findViewById(R.id.ll_add_group).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JoinCompanyActivity.start(getContext());
                dismiss();
            }
        });
    }

    public void setData(List<CompanyEntity> list){
        goodsTypeAdapter.setDatas(list);
    }

    public void setItem(int position){
        goodsTypeAdapter.setDefItem(position);
    }

    public interface DialogClickCallBack {
        void onItemClick(CompanyEntity provinceEntity,int position);
    }

    public CompanyChangeDialog setDialogClickCallBack(DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }
}
